		<script src="<{STATIC_SERVER}>/layui/layui.all.js"></script>
		<script>
			
			$(function (){
				//根据代理获取员工
				var form  = layui.form();
				form.on('select(aid)', function(data){
					var url = "/agent/ajax_get_staff";
					var aid = data.value;
					if (aid == "0") {
						$("select[name='sid']").html('<option value="0">不限制</option>');
						form.render('select');
					} else {
						http_request_post(url, {aid:aid}, function(result){
							$("select[name='sid']").html("");
							html = '<option value="0">全部员工</option>';
							if (result.status == 1) {
								var res = eval(result.data);
								$.each(res, function(key, val){
									html += '<option value="'+val.id+'">'+val.username+'</option>';
								})
							}
							$("select[name='sid']").html(html);
							form.render('select');
						});
					}
				});
				
				//更改导航选中状态
				$(".layui-nav-item").click(function (){
						$(".layui-nav-item").removeClass("layui-nav-itemed");
						if (! $(this).hasClass("layui-nav-itemed")) {
							$(this).addClass("layui-nav-itemed");
						} else {
							$(this).removeClass("layui-nav-itemed");
							$(this).find("dd").removeClass("layui-this");
						}
					})
					
				//获取服务器时间
				//get_system_time();
				//get_system_info();
			})
			var system_info = system_time = system_holiday = 0;
			var token = "<{$token}>";
			//获取系统时间
			var time = <{round(microtime(true) * 1000)}>;
			var n = t = 0; 
			function get_system_time() {
				//防止用户退出继续请求
				if (system_time >= 0) {
					t = new Date(time);
					n = (t.getHours() < 10 ? "0" :"") + t.getHours() + ":" + (t.getMinutes() < 10 ? "0" :"") + t.getMinutes() + ":" + (t.getSeconds() < 10 ? "0" :"") + t.getSeconds();
					$("#xinsu-system-time").html(n);
					time += 1000;
					system_time = setTimeout("get_system_time();", 1000);
				}
			}
			
			//获取系统时间
			function get_system_info() {
				//防止用户退出继续请求
				if (system_info >= 0) {
					var url = "/index/get_system_info";
					http_request_post(url, "", function(res) {
						var result = res.data;
						$("#xinsu-message").html(result.message);
						if (result.holiday == "休市") {
							system_holiday = 1;
						} else {
							system_holiday = 0;
						}
						system_info = setTimeout("get_system_info();", 1000);
					});
				}
			}

			//清除系统缓存
			function clear_system_cache() {
				layer.confirm('您确定要更新缓存？', {icon: 3}, function () {
					var url = "/index/clear_system_cache";
					layer.closeAll();
					http_request_post(url, null, function(res) {
						layer.msg(res.msg, {icon: 1,time: 800});
					});
				});
			}
					
			//退出登录
			function logout() {
				layer.confirm('您确定要退出？', {icon: 3}, function () {
					stock = system_info = -1
					var url = "/index/logout";
					layer.closeAll();
					http_request_post(url, null, function(res) {
						layer.msg(res.msg, {icon: 1, time: 800}, function () {
							//跳转到登录页面
							location.href = "/<{$common_info.module}>/index/login";
						});
					});
				});
			}
					
			//新增表单
			$(".xinsu-add a").click(function (){
				location.href = "/<{$common_info.module}>/<{$common_info.controller}>/add";
			})
					
			//修改表单
			$(".xinsu-edit").click(function (){
				var id = $(this).attr("data");
				location.href = "/<{$common_info.module}>/<{$common_info.controller}>/edit/" + id;
			})
					
			//删除数据
			$(".xinsu-delete").click(function (){
				var id = $(this).attr("data");
				var url = "/<{$common_info.controller}>/delete/" + id;
				layer.confirm('您确定要删除记录？', {icon: 3}, function () {
					layer.closeAll();
					http_request_post(url, {}, function (result) {
						if (result.status == 1) {
							layer.msg(result.msg, {icon: 1, time: 800}, function () {
									//跳转到登录页面
									location.reload();
								});
						} else {
							layer.msg(result.msg);
						}
					});
				});
			})
				
			//更新数据
			$(".xinsu-change").click(function (){
				var url = $(this).attr("data-uri");
				http_request_post(url, {}, function (result) {
					if (result.status == 1) {
						layer.msg(result.msg, {icon: 1, time: 800}, function () {
							var res = eval(result.data);
							var id = res["id"];
							var field = res["field"];
							var is_field = res[field];
							if (is_field == 1) {
								if (field == "locked") {
									var msg = "解锁";
								} else if (field == "disable") {
									var msg = "启用";
								} else {
									var msg = "开仓";
								}
								$("#xinsu-"+field+"-" + id).html(msg);
								$("#xinsu-"+field+"-" + id).removeClass("xinsu-fontcolor-blue");
								$("#xinsu-"+field+"-" + id).addClass("xinsu-fontcolor-red");
							} else {
								if (field == "locked") {
									var msg = "锁定";
								} else if (field == "disable") {
									var msg = "禁用";
								} else {
									var msg = "停仓";
								}
								$("#xinsu-"+field+"-" + id).html(msg);
								$("#xinsu-"+field+"-" + id).removeClass("xinsu-fontcolor-red");
								$("#xinsu-"+field+"-" + id).addClass("xinsu-fontcolor-blue");
							}
						});
					} else {
						layer.msg(result.msg);
					}
				});
			})
					
			//股票K线图弹出框
			$('.xinsu-stock-figure').click(function(){
				var data = $(this).attr("data");
				layer.open({ 
					type: 1,
					title: '股票代码：' + data +' K线图',
					area: ['550px', '400px'],
					shadeClose: true,
					content: '<div class="layui-tab layui-tab-card" style="margin:0; height:99%;"><ul class="layui-tab-title"><li class="layui-this">分时线</li><li>日K线</li><li>周K线</li><li>周K线</li></ul><div class="layui-tab-content" style="height: 100px;"><div class="layui-tab-item layui-show"><img style="width:100%" src="http://image2.sinajs.cn/newchart/min/n/'+data+'.gif"></div><div class="layui-tab-item"><img  style="width:100%" src="http://image2.sinajs.cn/newchart/daily/n/'+data+'.gif"></div><div class="layui-tab-item"><img  style="width:100%" src ="http://image2.sinajs.cn/newchart/weekly/n/'+data+'.gif"></div><div class="layui-tab-item"><img  style="width:100%" src ="http://image2.sinajs.cn/newchart/monthly/n/'+data+'.gif"></div></div></div>'
				});
			});
					
			//用户信息弹出框
			$('.xinsu-user').click(function(){
				var id = $(this).attr("data");
				http_request_post("/user/get_user_info", {id : id}, function (result) {
					if (result.status == 1) {
						var res = eval(result.data);
						if (res.demo_account == 0) {
							var demo_account = "正式";
						} else {
							var demo_account = "试玩";
						}
						layer.open({ 
							type: 1,
							title: '会员 ' + id + ":" + res.username + ' 详细信息',
							area: ['600px', '380px'],
							shadeClose: true, //点击遮罩关闭
							content: '<div class="layui-form xinsu-form"><table class="layui-table xinsu-table"><tbody><tr><td>会员账号</td><td style="text-align: left">'+res.username+'</td><td>姓名</td><td style="text-align: left">'+res.realname+'</td></tr><tr><td>账号类型</td><td style="text-align: left">'+demo_account+'</td><td>手机</td><td style="text-align: left">'+res.mobile+'</td></tr><tr><td>保证金</td><td style="text-align: left">￥'+res.finance+'</td><td>可用额度</td><td style="text-align: left">￥'+res.amount+'</td></tr><tr><td>持仓金额</td><td style="text-align: left">￥'+res.bull_money+'</td><td>总资产</td><td style="text-align: left">￥'+res.total_assets+'</td></tr><tr><td>浮动盈亏</td><td style="text-align: left">￥'+res.total_gain+'</td><td>净资产</td><td style="text-align: left">￥'+res.net_assets+'</td></tr><tr><td>保证金率</td><td style="text-align: left">'+res.ratio+'%</td><td>可提现金额</td><td style="text-align: left">￥'+res.cash+'</td></tr><tr><td>注册时间</td><td style="text-align: left">'+res.reg_date+'</td><td>最后登录时间</td><td style="text-align: left">'+res.last_login+'</td></tr><tr><td>上级代理</td><td style="text-align: left">'+res.agent_name+'</td><td>所属员工</td><td style="text-align: left">'+res.staff_name+'</td></tr></tbody></table></div>'
						});
					}
				})
			});
			$('.xinsu-content').click(function(){
				var url = $(this).attr("data-uri");
				var title = $(this).attr("data-title");
				layer.open({
						type: 2,
						title: title,
						shadeClose: true,
						area: ['550px', '250px'],
						skin: 'layui-layer-rim', //加上边框
						content:[ url ,'auto' ] //iframe的url
					});
			});		
			//发送短信或站内信
			$(".xinsu-send-sms").click(function(){
				var id = $(this).attr('data-id');
				var url = "/sms/ajax_get_user_info";
				
				http_request_post(url, {id:id}, function(result){
					if(result.status==1){
						var username = result.data.username,realname = result.data.realname,phone = result.data.mobile,sex = result.data.sex;
						layer.open({ 
							type: 1,
							title: '会员'+id+' 的详细信息',
							area: ['550px', '400px'],
							btn:['确定', '取消'],
							shadeClose: true, //点击遮罩关闭
							content: '<div style="padding:10px 40px 0 40px; line-height:36px; font-size:14px;">'+
							'<form class="xinsu-form">'+
							'<table class="layui-table xinsu-table">'+
							'<tbody>'+
							'<tr><td nowrap="nowrap">发送用户：</td><td style="text-align: left;">'+username+'('+realname+') </td></tr>'+
							'<tr><td nowrap="nowrap">手机号码：</td><td style="text-align: left;">'+phone+'</td></tr>'+
							'<tr><td nowrap="nowrap">模板：</td><td align="left" nowrap="nowrap"><div align="left">'+
							'<input type="radio" name="msg_type" value="1" checked onclick="javascript:$(\'#content\').val(\'尊敬的'+realname+sex+'，您好！账号'+username+'已为您激活,初始密码：abc123，网址<{$_SERVER["HTTP_HOST"]}>,请点击会员登录进入，请收到账号后及时登录交易平台修改初始密码，若需相关咨询，请拔打客服热线0371-53690183，恭祝您生活愉快\');$(\'#xinsu-sms-title\').hide();">账户&nbsp;&nbsp;'+
							'<input type="radio" name="msg_type"  value="2"  onclick="javascript:$(\'#content\').val(\'尊敬的'+realname+sex+'，您好！账号'+username+'浮动亏损过大，请您注意风险，随时关注账户变化情况。\');$(\'#xinsu-sms-title\').hide();">风险&nbsp;&nbsp;'+
							'<input type="radio" name="msg_type" value="3" onclick="javascript:$(\'#content\').val(\'尊敬的'+realname+sex+'，您好！账号'+username+'保证金率低于50%，请于当天20:00点之前补足100%，如未能在当天补足，则系统将于次个交易日开市后将超出部分按比例以市价平仓。\');$(\'#xinsu-sms-title\').hide();">追加&nbsp;&nbsp;'+
							'<input type="radio" name="msg_type" value="4" onclick="javascript:$(\'#content\').val(\'尊敬的'+realname+sex+'，您好！账号'+username+'中(代码)明日除权除息，请予今日下午收盘前平仓该订单，若您未自行平仓，则系统会强制平仓，谢谢合作。\');$(\'#xinsu-sms-title\').hide();">除权&nbsp;&nbsp;'+
							'<input type="radio" name="msg_type" value="5" onclick="javascript:$(\'#content\').val(\'尊敬的'+realname+sex+'，您好！账号'+username+'有定单留仓天数到达规定天数10天，建议您随时关注，选择合适价位平仓，否则系统会在收盘前平仓您留仓10天的定单，若需相关咨询，请拔打客服热线0371-53690183，恭祝您生活愉快。\');$(\'#xinsu-sms-title\').hide();">留仓&nbsp;&nbsp;'+
							'<input type="radio" name="msg_type" value="6" onclick="javascript:$(\'#content\').val(\'自己编写手机短信\');$(\'#xinsu-sms-title\').hide();">自编&nbsp;&nbsp;'+
							'<input type="radio" name="msg_type" value="7" onclick="javascript:$(\'#content\').val(\'自己编写站内信\');$(\'#xinsu-sms-title\').show();">站内'+
							'</div></td></tr><tr id="xinsu-sms-title" style="display:none;"><td>标题：</td><td><div align="left"><input type="text" name="title" id="title" size=45></div></td></tr>'+
							'<tr><td nowrap="nowrap">内容：</td><td><div align="left"><textarea name="content" id="content" cols="50" rows="6">尊敬的'+realname+sex+'，您好！账号'+username+'已为您激活,初始密码：abc123，网址<{$_SERVER["HTTP_HOST"]}>,请点击会员登录进入，请收到账号后及时登录交易平台修改初始密码，若需相关咨询，请拔打客服热线0371-53690183，恭祝您生活愉快。</textarea></div></td></tr>'+
							'</tbody></table></form></div>',
							yes:function(index, layers){
								var title = $("#title").val();
								var type = $("input[name='msg_type']:checked").val();
								var content = $("#content").val();
								url = "/sms/send";
								layer.closeAll();
								http_request_post(url, {id:id,phone:phone, title:title, type:type,content:content}, function(result){
									layer.msg(result.msg, {icon:1, time:800}, function(){});
								});
							}
						});		
					} else {
						layer.msg(result.msg);
					}
				});
			});
				
			//提交表单
            var sub = 0;
			$("form").submit(function () {
				//判断提交方式：get-搜索专用，post-保存专用
				var method = $(this).attr("method");
				if (method == "post") {
					//保存专用
					var data = $(this).serialize();
					data += "&token="+token;
					layer.confirm('您确定要执行？', {icon: 3}, function () {
                        sub += 1;
						layer.closeAll();
                        if (sub == 1) {
                            http_request_post("", data, function (result) {
                                layer.msg(result.msg, {icon:1, time:800}, function (){
                                    if (result.data != "") {
                                        location.href = "/<{$common_info.module}>" + result.data;
                                    } else {
                                        location.reload();
                                    }
                                });
                            });
                        }
					});
					return false;
				} else {
					//搜索专用
					var data = $(this).serializeArray();
					var	url = "/<{$common_info.module}>/<{$common_info.controller}>/<{$common_info.action}>";
					$.each(data, function(key, val) {
							if (val.value == "") {
								url += "/0";
							} else {
								url += "/" + val.value;
							}
						});
					location.href = url;
					return false;
				}
			})
					
					
			//通用post请求
			function http_request_post(url, data, callback) {
				if (url != "") {
					url = "/<{$common_info.module}>" + url;
				}	
				$.ajax({
					type : 'post',  
					url : url,
					dataType : 'json',
					data : data,
					success : function(repones) {
						if (repones.status == 1) {
							if (typeof callback === "function") {
								callback(repones);
								return false;
							} else {
								layer.msg('请求加载数据失败，请重新加载');
							}
						} else if (repones.status == 2) {
							layer.msg(repones.msg, {icon:0, time:800}, function (){
								location.href = "/<{$common_info.module}>/index/login";
							});
						}  else if (repones.status == 0) {
							token = repones.token;
							layer.msg(repones.msg);
							return false;
						} else {
							layer.msg(repones.msg);
							return false;
						}
					},
					error : function () {  
						layer.msg('加载数据失败，请重新加载');
						return false;
					}
				});
				return false;
			}
		</script>
	</body>
</html>